package com.gewu.pm.ui.activity.customer;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.androidkun.xtablayout.XTabLayout;
import com.gewu.pm.R;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.app.AppFragment;
import com.gewu.pm.other.IntentKey;
import com.gewu.pm.ui.fragment.delivery.DeliveryContactFragment;
import com.gewu.pm.ui.fragment.delivery.DeliveryDetailFragment;
import com.gewu.pm.ui.fragment.delivery.DeliveryTerminalFragment;
import com.hjq.base.FragmentPagerAdapter;

/**
 * 配送商详情页面
 * 
 * 功能：
 * 1. Tab切换（详情、终端、联系人）
 * 2. 顶部信息卡片固定显示
 * 3. 支持搜索终端
 * 4. 支持拨打电话
 */
public final class DeliveryProviderDetailsActivity extends AppActivity {

    private XTabLayout mTabLayout;
    private ViewPager mViewPager;
    private TextView mProviderNameView;
    private TextView mVehicleCodeView;
    private TextView mSalesAreaView;
    private TextView mDepartmentView;
    
    private FragmentPagerAdapter<AppFragment<?>> mPagerAdapter;

    /**
     * 启动配送商详情页面
     * 
     * @param context 上下文
     * @param providerName 配送商名称
     */
    public static void start(Context context, String providerName) {
        Intent intent = new Intent(context, DeliveryProviderDetailsActivity.class);
        intent.putExtra(IntentKey.NAME, providerName);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.delivery_provider_details_activity;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mTabLayout = findViewById(R.id.tab_layout);
        mViewPager = findViewById(R.id.view_pager);
        mProviderNameView = findViewById(R.id.tv_provider_name);
        mVehicleCodeView = findViewById(R.id.tv_vehicle_code);
        mSalesAreaView = findViewById(R.id.tv_sales_area);
        mDepartmentView = findViewById(R.id.tv_department);
    }

    @Override
    protected void initData() {
        // 获取传递的配送商名称
        String providerName = getString(IntentKey.NAME);
        if (providerName != null && !providerName.isEmpty()) {
            mProviderNameView.setText(providerName);
        }

        // 初始化 FragmentPagerAdapter
        mPagerAdapter = new FragmentPagerAdapter<>(this);
        mPagerAdapter.addFragment(DeliveryDetailFragment.newInstance(), getString(R.string.delivery_detail_tab));
        mPagerAdapter.addFragment(DeliveryTerminalFragment.newInstance(), getString(R.string.delivery_terminal_tab));
        mPagerAdapter.addFragment(DeliveryContactFragment.newInstance(), getString(R.string.delivery_contact_tab));
        mViewPager.setAdapter(mPagerAdapter);
        
        // 关联 XTabLayout 和 ViewPager
        mTabLayout.setupWithViewPager(mViewPager);
    }
}

